package com.frogs.ucenter.v1.request;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import com.frogs.framework.web.HttpRequestInfo;
import com.frogs.system.util.ApiUrlParamEnum;
import com.frogs.system.web.api.request.Request;
import com.frogs.system.web.exception.RequestIllegalException;
import com.frogs.ucenter.entity.UserLevelInfo;
import com.frogs.ucenter.entity.UserPointLog;

public class UserLevelInfoSaveRequest extends Request {
	
	private UserLevelInfo userLevelInfo = new UserLevelInfo();
	private UserPointLog userPointLog = new UserPointLog();
	
	private int id;
    private Integer dynamicVipLevel = 0;
    private Date dynamicVipDeadline = new Date();
    private Integer level = 0;
    private String upRuleCode = null;
    private Integer applicablePlatformId = 0;

	public UserLevelInfoSaveRequest() {
	}
	
	@Override
	public void parse(HttpServletRequest request) {
		HttpRequestInfo requestInfo = new HttpRequestInfo(request);
		this.id = requestInfo.getIntParameter(ApiUrlParamEnum.userId.getParamName(), 0);
		
		if(id == 0) {
			throw new RequestIllegalException("缺少用户id，请确认!");
		}
		userLevelInfo.setId(id);
		
		this.dynamicVipLevel = requestInfo.getIntParameter(ApiUrlParamEnum.dynamicVipLevel.getParamName(),0);
		if(dynamicVipLevel != 0) {
			userLevelInfo.setDynamicVipLevelId(dynamicVipLevel);
		}
		
		this.dynamicVipDeadline = requestInfo.getDateParameter(ApiUrlParamEnum.dynamicVipDeadline.getParamName(), "yyyy-MM-dd HH:mm:ss");
		if(null != dynamicVipDeadline) {
			userLevelInfo.setDynamicVipDeadline(dynamicVipDeadline);
		}
		
		this.level = requestInfo.getIntParameter(ApiUrlParamEnum.level.getParamName(),0);
		if(level != 0) {
			userLevelInfo.setLevelId(level);
		}
		
		this.upRuleCode = requestInfo.getParameter(ApiUrlParamEnum.upRuleCode.getParamName());
		this.applicablePlatformId = requestInfo.getIntParameter(ApiUrlParamEnum.applicablePlatformId.getParamName(), 0);
		
	}

	public UserLevelInfo getUserLevelInfo() {
		return userLevelInfo;
	}

	public void setUserLevelInfo(UserLevelInfo userLevelInfo) {
		this.userLevelInfo = userLevelInfo;
	}
	
	public Integer getApplicablePlatformId() {
		return applicablePlatformId;
	}

	public void setApplicablePlatformId(Integer applicablePlatformId) {
		this.applicablePlatformId = applicablePlatformId;
	}

	public String getUpRuleCode() {
		return upRuleCode;
	}

	public void setUpRuleCode(String upRuleCode) {
		this.upRuleCode = upRuleCode;
	}
	public UserPointLog getUserPointLog() {
		return userPointLog;
	}

	public void setUserPointLog(UserPointLog userPointLog) {
		this.userPointLog = userPointLog;
	}
}
